package xkp.lesson5;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class TestStream {
    public static void main(String[] args) {
        String[] strs = {"aBc","heLlo","Yes","No"};
        List<String> stringList = Arrays.asList(strs);
        //返回一个全是大写的List集合
        //返回一个全是小写的List集合
        //根据集合创建Stream
        Stream<String> stringStream = stringList.stream();
        //操作流
        //<R> Stream<R> map(Function<? super T, ? extends R> mapper);
        //map方法把传进来的每一个对象映射为新的对象然后组合成一个新的流
/*        stringStream.map(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.toUpperCase();
            }
        });*/
        Stream<String> upperStream = stringStream.map(x->x.toUpperCase());
        //把Stream转换为List
        List<String> upperList = upperStream.collect(Collectors.toList());
        upperList.forEach(System.out::println);
        System.out.println("**************************");
        stringList.stream().map(x->x.toLowerCase()).forEach(System.out::println);
        //过滤
    }
}
